﻿using MyWebApp.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace MyWebApp.Common.UIAttribute
{
    public class LayoutAttribute : ActionFilterAttribute
    {
        public override void OnResultExecuting(ResultExecutingContext filterContext)
        {
            base.OnResultExecuting(filterContext);
            //获取共通信息 
            //实际情况下 通过缓存提供效率
            ((ViewResult)filterContext.Result).ViewBag.SysTitle = "AdminLTE后台管理系统";
            ((ViewResult)filterContext.Result).ViewBag.CurUrl = filterContext.RequestContext.HttpContext.Request.Path;
            ((ViewResult)filterContext.Result).ViewBag.CommolModels = GetModel();
        }

        private AdminModels GetModel()
        {
            AdminModels model = new AdminModels();
            model.Menus = new List<MenuItem>();
            //model.Menus.Add(new MenuItem() { Id = "01", Name = "首页", Index = 1, ParentID = "0", Icon = "fa-dashboard" });
            //model.Menus.Add(new MenuItem() { Id = "0101", Name = "首页1", Index = 1, ParentID = "01", Icon = "fa-circle-o" });
            model.Menus.Add(new MenuItem() { Id = "02", Name = "系统管理", Index = 9, ParentID = "0", Icon = "fa-table" });

            model.Menus.Add(new MenuItem() { Id = "03", Name = "基础管理", Index = 3, ParentID = "0", Icon = "fa-table" });
            model.Menus.Add(new MenuItem() { Id = "0201", Name = "用户管理", Index = 1, ParentID = "02", Icon = "fa-circle-o" });
            model.Menus.Add(new MenuItem() { Id = "020101", Name = "用户管理", Index = 1, ParentID = "0201", Icon = "fa-link", Url = "/Sys/User/Index" });
            model.Menus.Add(new MenuItem() { Id = "020102", Name = "角色管理", Index = 1, ParentID = "0201", Icon = "fa-link" });

            model.Menus.Add(new MenuItem() { Id = "0202", Name = "系统管理", Index = 2, ParentID = "02", Icon = "fa-circle-o" });
            model.Menus.Add(new MenuItem() { Id = "020201", Name = "参数管理", Index = 1, ParentID = "0202", Icon = "fa-link" });
            model.Menus.Add(new MenuItem() { Id = "020202", Name = "日志管理", Index = 1, ParentID = "0202", Icon = "fa-link" });

            model.CurUser = new LoginUserModel()
            {
                UserId = "admin",
                UserImg = "a.png",
                UserName = "管理员",
                UserDept = "成都-管理员",
                Remarks = "没啥说的",
                Roles = new List<string>()
            };
            model.CurUser.Roles.Add("管理员");
            model.CurUser.Roles.Add("研发");
            model.CurUser.Roles.Add("产品经理");

            model.MyNotification = new List<NotificationModel>();
            model.MyNotification.Add(new NotificationModel() { id = 1, Type = "users", Content = "用户信息1" });
            model.MyNotification.Add(new NotificationModel() { id = 2, Type = "users", Content = "用户信息2" });
            model.MyNotification.Add(new NotificationModel() { id = 3, Type = "users", Content = "用户信息3" });
            model.MyNotification.Add(new NotificationModel() { id = 4, Type = "warning", Content = "警告" });

            return model;
        }
    }
}